<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>部门管理</title>
    <title>vue-demo1</title>
    <script src="/js/vue.js"></script>
    <link rel="stylesheet" href="/css/index.css">
    <script src="/js/index.js"></script>
    <script src="/js/axios.min.js"></script>
</head>
<body>
<div id="app">
    <!--查询-->
    <el-row>
        <el-col :span="4"><el-input  v-model="searchForm.name"  size="small" placeholder="请输入医生名字"></el-input></el-col>
        <el-col :span="4"><el-button type="primary" @click="search" size="small" icon="el-icon-search">搜索</el-button></el-col>
<!--        <el-col :span="4"><el-button type="primary" @click="handlerAdd"  size="small" icon="el-icon-circle-plus">添加</el-button></el-col>-->
        <el-col :span="4"></el-col>
        <el-col :span="4"></el-col>
    </el-row>
    <!--表格显示-->
    <el-table
            :data="tableData"
            style="width: 100%">
        <el-table-column
                prop="id"
                label="id">
        </el-table-column>
        <el-table-column
                prop="name"
                label="医生名字">
        </el-table-column>
        <el-table-column
                prop="money"
                label="花费">
        </el-table-column>
        <el-table-column
                prop="sname"
                label="患者名字">
        </el-table-column>
        <el-table-column
                prop="card"
                label="身份证号码">
        </el-table-column>
        <el-table-column
                prop="time"
                label="时间">
        </el-table-column>
        <el-table-column
                prop="status"
                label="状态">
            <template slot-scope="scope">
                <el-tag
                        :type="scope.row.status == 0 ? 'danger' : 'success'"
                        disable-transitions>{{scope.row.status == 0 ? "未支付" : "已支付"}}
                </el-tag>
            </template>
        </el-table-column>
        <el-table-column
                prop="orders"
                label="处理状态">
            <template slot-scope="scope">
                <el-tag
                        :type="scope.row.orders == 0 ? 'danger' : 'success'"
                        disable-transitions>{{scope.row.orders == 0 ? "未处理" : "同意预约"}}
                </el-tag>
            </template>
        </el-table-column>
        <el-table-column label="操作">
            <template slot-scope="scope">
                <el-button
                        size="mini"
                        @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
   <!--             <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.$index, scope.row)">删除</el-button>-->
            </template>
        </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[2,5,10,15,20]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
    </el-pagination>
    <!--更新对话框-->
    <el-dialog :title="title" :visible.sync="dialogFormVisible">
        <el-form :model="form">
            <!--<el-form-item label="医生名字" :label-width="formLabelWidth">
                <el-input v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="花费" :label-width="formLabelWidth">
                <el-input v-model="form.money" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="患者名字" :label-width="formLabelWidth">
                <el-input v-model="form.sname" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="身份证号码" :label-width="formLabelWidth">
                <el-input v-model="form.card" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="时间" prop="time" :label-width="formLabelWidth">
                <el-date-picker type="date" placeholder="选择日期" v-model="form.time" style="width: 100%;"></el-date-picker>
            </el-form-item>-->
            <el-form-item label="状态" :label-width="formLabelWidth">
              <!--  <el-input v-model="form.status" autocomplete="off"></el-input>-->
                <el-select v-model="form.orders" placeholder="请选择活动区域">
                    <el-option label="未处理" value="0"></el-option>
                    <el-option label="同意预约" value="1"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="addOrUpdate">确 定</el-button>
        </div>
    </el-dialog>

</div>
<script>
    //Vue.component();  //组件->模板


    var app = new Vue({
            el:"#app",
            //存放所有js对象的  plain  javascript object
            data(){
                return{
                    tableData: [], //表格数据
                    currentPage: 1,//当前页 第几页
                    pageSize: 5,//每页显示数量
                    total: 400,//总条数
                    searchForm:{name:''},//搜索对象
                    title: '添加', //弹出框标题
                    dialogFormVisible: false,//对话框是否显示
                    form: { //form表单对象
                        id:'',
                        name: '',
                        money: '',
                        sname: '',
                        card: '',
                        time: '',
                        status: '',
                        orders:'',
                    },
                    rules: {
                        time: [
                                { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
                        ],
                    },
                    formLabelWidth: '120px' //form中label的宽度
                }
            },
            //所有页面元素触发的事件的方法
            methods:{
                //封装的加载数据方法
                loadData(){
                    //定义一个变量，赋值为当前vue对象
                    var _this = this;
                    //使用axios向后台发请求，获取数据
                    axios.get(//请求方式，必须和后端资源暴露方式一致
                        '/regi/queryTreeDataByUserName',//请求的url
                        {"pageNo":this.currentPage,"pageSize":this.pageSize,

                             "data":{"inspectName":this.searchForm.inspectN,"fee":this.searchForm.feE}}) //请求携带的参数


                        .then(function (response) {//成功响应的处理方法   response 是响应的数据
                            console.log(response);
                            //response 一定是json对象  stringify 把json对象转json字符串
                            //alert(JSON.stringify(response));
                            //判断返回是否正确
                            if(response.data.code==200){
                                //直接使用this 代表axios的对象  this
                                _this.tableData=response.data.data;
                                _this.total=response.data.data.total;
                            }else{
                            }
                        })
                        .catch(function (error) {
                            console.log(error);
                        });
                },
                //处理每页数量发生变化
                handleSizeChange(val) {
                    console.log(`每页 ${val} 条`);
                    //让每页数量发生改变
                    this.pageSize=val;
                    //调用加载数据方法
                    this.loadData();
                },
                //处理当前页（页码 第几页）发生变化
                handleCurrentChange(val) {
                    console.log(`当前页: ${val}`);
                    //让第几页发生改变
                    this.currentPage=val;
                    //调用加载数据方法
                    this.loadData();
                },
                //按条件查询
                search(){
                    //直接调用loadData
                    this.loadData();
                },
                //处理添加
                handlerAdd(){
                    //修改标题
                    this.title='添加';
                    //清空原来的值
                    this.form={};
                    //让对话框显示
                    this.dialogFormVisible = true;
                },
                //处理更新
                handleEdit(index, row) {
                    console.log(index, row);
                    this.title = '更新';
                    this.form = row;
                    //alert(JSON.stringify(this.form));
                    //让对话框显示
                    this.dialogFormVisible = true;
                },
//调用接口添加或者更新数据
                addOrUpdate() {
                    //定义url
                    var url = "/registration/add";
                    //判断是否添加还是更新
                    if (this.title === '更新') {
                        url = "/regi/updateBy";
                    }
                    //定义一个变量，赋值为当前vue对象
                    var _this = this;
                    //使用axios向后台发请求，获取数据
                    //axios.post('http://172.16.7.66:8080/dept/queryByPage', {
                    axios.put(//请求方式，必须和后端资源暴露方式一致
                        url,//请求的url
                        this.form)
                        .then(function (response) {//成功响应的处理方法   response 是响应的数据
                            console.log(response);
                            //response 一定是json对象  stringify 把json对象转json字符串
                            //alert(JSON.stringify(response));
                            //判断返回是否正确
                            if (response.data.code == 200) {
                                //提示信息
                                _this.$message({
                                    message: '恭喜你，这是一条成功消息',
                                    type: 'success'
                                });
                                //关闭对话框
                                _this.dialogFormVisible = false;
                                //重新加载数据
                                _this.loadData();
                            } else {
                                _this.$message.error('错了哦，这是一条错误消息');
                            }
                        })
                        .catch(function (error) {
                            console.log(error);
                        });
                },
                //处理删除
                handleDelete(index, row) {
                    this.$confirm('此操作将永久删除该数据，是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        axios.delete('/regi/delete', {params: {id: row.id}}).then(response => {
                            if (response.data.code == 200) {
                                this.loadData();
                                this.$message.success('删除成功了')
                            } else {
                                this.$message.success('删除失败了')
                            }
                        }).catch(function (error) {
                            console.log(error);
                            this.$message.success('删除失败了')
                        });
                    })}
            },
          /*  beforeCreate(){
               alert("创建前----");
            },*/
            created(){//初始化操作
                //alert("创建后----");
                this.loadData()
            },
        }
    )
</script>
</body>
</html>
